using System;
using Kopernikus.Parsing.Utility;

namespace Kopernikus.Parsing.Earley
{
    public struct EarleyLink : IEquatable<EarleyLink>
    {
        private Pair<EarleySetItem, EarleySetItem> m_data;

        public EarleySetItem Predecessor
        {
            get { return m_data.First; }
        }

        public EarleySetItem Causal
        {
            get { return m_data.Second; }
        }

        #region Object overrides

        public override string ToString()
        {
            return m_data.ToString();
        }

        public override bool Equals(object obj)
        {
            return Equals((EarleyLink) obj);
        }

        public override int GetHashCode()
        {
            return m_data.GetHashCode();
        }

        #endregion

        #region IEquatable<EarleyLink> Members

        public bool Equals(EarleyLink other)
        {
            return m_data.Equals(other.m_data);
        }

        #endregion

        public static EarleyLink Create(EarleySetItem predecessor, EarleySetItem causal)
        {
            EarleyLink earleyLink;
            earleyLink.m_data = Pair<EarleySetItem, EarleySetItem>.Create(predecessor, causal);
            return earleyLink;
        }
    }
}